package com.kaiyidiannao.activity.user_detail;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.*;
import com.kaiyidiannao.activity.SecondHandHouse.SecondHandHouseDetail;
import com.kaiyidiannao.activity.auction.AuctionDetailActivity;
import com.kaiyidiannao.activity.messageInfo.MessageInfoDetail;
import com.kaiyidiannao.activity.secondhandcar.SecondHandCarDetail;
import com.kaiyidiannao.activity.tour.TourLineDetailActivity;
import com.kaiyidiannao.adapter.*;
import com.kaiyidiannao.common.BaseActionBarActivity;
import com.kaiyidiannao.common.pulltorefresh_view.DragListView;
import com.kaiyidiannao.data.DataCenter;
import com.kaiyidiannao.https.HttpUtils;
import com.kaiyidiannao.main.R;
import com.kaiyidiannao.model.bean.*;
import com.kaiyidiannao.model.req.model.*;
import com.kaiyidiannao.view.ActionBarView;
import com.taplinker.core.util.LogUtil;

import java.util.*;

/**
 * Created by mark on 2014/4/16.
 */
public class MyPublish extends BaseActionBarActivity implements Observer {

    private MyAuctionAdapter myAuctionAdapter = null;
    private MySecondHandHouseAdapter mySecondHandHouseAdapter = null;
    private MySecondHandCarAdapter mySecondHandCarAdapter = null;
    private MyTourGatherAdapter myTourGatherAdapter = null;
    private MyTourSmallNoteAdapter myTourSmallNoteAdapter = null;
    private MessageAdapter messageAdapter = null;
    private DragListView baseList;
    private ListView categoryListview;
    private SimpleAdapter simpleAdapter;
    private List<Map<String, String>> data;
    private String[] categoryTextArrays = null; //分类数组的对应的文字
    private boolean isClose = true;
    private CheckBox checkbox_category;//展开分类的checkbox
    private String[] catids = {"66", "64", "65", "53", "54", "56"};
    private ArrayList<Auction> beansAuction = DataCenter.beansAuction;
    private ArrayList<SecondHandCar> beansCar = DataCenter.beansCar;
    ;
    private ArrayList<SecondHandHouse> beansHouse = DataCenter.beansHouse;
    ;
    private ArrayList<TourBean> beansGather = DataCenter.beansGather;
    private ArrayList<TourBean> beansSmall = DataCenter.beansSmall;
    private ArrayList<UserBean> userBeans = DataCenter.userLogin;
    private ArrayList<MessageBean> messageBeans = DataCenter.messageInfoList;
    private int currentPage = DataCenter.LISTVIEW_DEFAULT_PAGE;
    private View no_content_view;
    int a;
    private int o1 = 0;
    private int o2 = 0;
    private int o3 = 0;
    private int o4 = 0;
    private int o5 = 0;
    private int o = 0;
    TourBean tourBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.base_info);

        // actionbar_title = (TextView)findViewById(R.id.actionbar_title);
        // 添加观察者
        DataCenter.getInstance().addObserver(this);

        findActionBar();
        initCategoryData();
        findById();

    }

    @Override
    protected void onRestart() {
        if (DataCenter.userLogin.size() != 0) {
            if (catids[a].equals("66")) {
                new GetMyPublishAuction(DataCenter.pat_category_id[0] + "", userBeans.get(0).getUserid(), "17",currentPage).execute();
            } else if (catids[a].equals("64")) {
                new GetMyPublishSecondHandCar(DataCenter.secondHandCar_category_id, userBeans.get(0).getUserid(), "5",currentPage).execute();
            } else if (catids[a].equals("65")) {
                new GetMyPublishSecondHandHouse(DataCenter.secondHandHouse_category_id, userBeans.get(0).getUserid(), "28",currentPage).execute();
            } else if (catids[a].equals("53")) {
                new GetMyPublishGather(DataCenter.tour_category_id[0], userBeans.get(0).getUserid(), "31",currentPage).execute();
            } else if (catids[a].equals("54")) {
                new GetMyPublishSmall(DataCenter.tour_category_id[2], userBeans.get(0).getUserid(), "31",currentPage).execute();
            } else if (catids[a].equals("56")) {
                new PostMyMessageInfo(56, userBeans.get(0).getUserid(), "30",currentPage).execute();
            }
        } else {
            showToast(getText(R.string.no_network).toString());
        }
        super.onRestart();
    }

    public void findById() {
        categoryListview = (ListView) findViewById(R.id.category_listview);
        baseList = (DragListView) findViewById(R.id.baseList);
        no_content_view = findViewById(R.id.no_content_view);

        Log.d("data", data.get(0).get("title") + "");
        simpleAdapter = new SimpleAdapter(this, data, R.layout.mypubilsh_animation_item, new String[]{"title"}, new int[]{R.id.itemTv});
        categoryListview.setAdapter(simpleAdapter);

//        categoryListview.post(new Runnable() {
//            public void run() {
//                Log.d("baseList.getChildCount()", categoryListview.getChildCount()+"----");
//                // fileList为与adapter做贯穿连接的list总数
//                if (data.size() == categoryListview.getChildCount()) {
//                    TextView textview = null;
//                    ImageView imageView = null;
//                    //对ListView中的ChildView进行操纵。。。
//                    textview = (TextView) categoryListview.getChildAt(DataCenter.index8).findViewById(R.id.itemTv);
//                    imageView = (ImageView) categoryListview.getChildAt(DataCenter.index8).findViewById(R.id.itemIv);
//                    textview.setTextColor(getResources().getColor(R.color.title_detail_color));
//                    imageView.setVisibility(View.VISIBLE);
//                }
//            }
//        });

        categoryListview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                DataCenter.index8 = i;
                isClose = true;
                a = i;
                currentPage = 1;
                for (int j = 0; j < categoryListview.getChildCount(); j++) {
                    if (j != i) {
                        TextView textview = (TextView) categoryListview.getChildAt(j).findViewById(R.id.itemTv);
                        ImageView imageView = (ImageView) categoryListview.getChildAt(j).findViewById(R.id.itemIv);
                        textview.setTextColor(getResources().getColor(R.color.font_black));
                        imageView.setVisibility(View.GONE);
                    } else {
                        TextView textview = (TextView) categoryListview.getChildAt(j).findViewById(R.id.itemTv);
                        ImageView imageView = (ImageView) categoryListview.getChildAt(j).findViewById(R.id.itemIv);
                        textview.setTextColor(getResources().getColor(R.color.title_detail_color));
                        imageView.setVisibility(View.VISIBLE);
                        if (catids[i].equals("66")) {//拍拍乐
                            new GetMyPublishAuction(DataCenter.pat_category_id[0] + "", userBeans.get(0).getUserid(), "17",currentPage).execute();
                            showProgressDialog("正在加载");
                            o1 = 0;
                        } else if (catids[i].equals("64")) {//二手车
                            Log.d("GetMyPublishSecondHandCar", i + "");
                            new GetMyPublishSecondHandCar(DataCenter.secondHandCar_category_id, userBeans.get(0).getUserid(), "5",currentPage).execute();
                            showProgressDialog("正在加载");
                            o2 = 0;
                        } else if (catids[i].equals("65")) {//二手房
                            Log.d("GetMyPublishSecondHandHouse", i + "");
                            new GetMyPublishSecondHandHouse(DataCenter.secondHandHouse_category_id, userBeans.get(0).getUserid(), "28",currentPage).execute();
                            showProgressDialog("正在加载");
                            o3 = 0;
                        } else if (catids[i].equals("53")) {//召集
                            new GetMyPublishGather(DataCenter.tour_category_id[0], userBeans.get(0).getUserid(), "31",currentPage).execute();
                            showProgressDialog("正在加载");
                            o4 = 0;
                        } else if (catids[i].equals("54")) {//微记
                            new GetMyPublishSmall(DataCenter.tour_category_id[2], userBeans.get(0).getUserid(), "31",currentPage).execute();
                            showProgressDialog("正在加载");
                            o5 = 0;
                        } else if (catids[i].equals("56")) {//信息矿
                            if (userBeans.size() == 0) {
//                                Toast.makeText(MyPublish.this, "网络连接异常,请稍后,在MYPUBLISH---信息矿", Toast.LENGTH_SHORT).show();
                                return;
                            }
                            new PostMyMessageInfo(56, userBeans.get(0).getUserid(), "30",currentPage).execute();
                            o = 0;
                            showProgressDialog("正在加载");
                        }
                    }
                }

                DataCenter.index2 = i;

                simpleAdapter.notifyDataSetChanged();
                // findById(); //刷新顶部分类
                closeTopBar();
                //设置category默认文字
                actionBarView.setTitle(categoryTextArrays[i]);
            }

        });


        baseList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.d("position", position + "");
                if (catids[a].equals("66")) {//拍拍乐
                    Auction auction = beansAuction.get(position - 1);
                    Intent intent = new Intent(MyPublish.this, AuctionDetailActivity.class);
                    intent.putExtra("catid", auction.getCatid());
                    intent.putExtra("itemid", auction.getItemid());
                    startActivity(intent);
                } else if (catids[a].equals("64")) {//二手车
                    SecondHandCar secondHandCar = beansCar.get(position - 1);
                    Intent intent = new Intent(MyPublish.this, SecondHandCarDetail.class);
                    intent.putExtra("catid", secondHandCar.getCatid());
                    intent.putExtra("itemid", secondHandCar.getItemid());
                    intent.putExtra("addtime", secondHandCar.getAddtime());
                    startActivity(intent);
                } else if (catids[a].equals("65")) {//二手房
                    SecondHandHouse secondHandHouse = beansHouse.get(position - 1);
                    Intent intent = new Intent(MyPublish.this, SecondHandHouseDetail.class);
                    intent.putExtra("catid", secondHandHouse.getCatid());
                    intent.putExtra("itemid", secondHandHouse.getItemid());
                    intent.putExtra("addtime", secondHandHouse.getAddtime());
                    startActivity(intent);
                } else if (catids[a].equals("53")) {//召集
                    tourBean = beansGather.get(position - 1);
                    Intent intent = new Intent(MyPublish.this, TourLineDetailActivity.class);
                    intent.putExtra("catid", DataCenter.CATID_TOUR_GATHER); // 这里的值是固定
                    intent.putExtra("itemid", tourBean.getItemid());
                    startActivity(intent);
                    currentPage = position / 10 + 1;
                } else if (catids[a].equals("54")) {//微记
                    TourBean tourBean = beansSmall.get(position - 1);
                    Intent intent = new Intent(MyPublish.this, TourLineDetailActivity.class);
                    intent.putExtra("catid", DataCenter.CATID_TOUR_SMALL_NOTE); // 这里的值是固定
                    intent.putExtra("itemid", tourBean.getItemid());
                    startActivity(intent);
                } else if (catids[a].equals("56")) {//信息矿
//                    messageBeans = DataCenter.messageInfoList;
                    MessageBean tourBean = messageBeans.get(position - 1);
                    Intent intent = new Intent(MyPublish.this, MessageInfoDetail.class);
                    intent.putExtra("catid", tourBean.getCatid());
                    intent.putExtra("itemid", tourBean.getItemid());
                    startActivity(intent);
                }

                DataCenter.mypub_position = position-1;
                DataCenter.PAGE = (position-1)/20+1;
                currentPage = (position-1)/20+1;
            }
        });

        baseList.setOnRefreshListener(new DragListView.OnRefreshLoadingMoreListener() {
            @Override
            public void onRefresh() {
                if (DataCenter.userLogin.size() != 0) {
                    currentPage = 1;
                    if (catids[a].equals("66")) {
                        new GetMyPublishAuction(DataCenter.pat_category_id[0] + "", userBeans.get(0).getUserid(), "17",currentPage).execute();
                    } else if (catids[a].equals("64")) {
                        new GetMyPublishSecondHandCar(DataCenter.secondHandCar_category_id, userBeans.get(0).getUserid(), "5",currentPage).execute();
                    } else if (catids[a].equals("65")) {
                        new GetMyPublishSecondHandHouse(DataCenter.secondHandHouse_category_id, userBeans.get(0).getUserid(), "28",currentPage).execute();
                    } else if (catids[a].equals("53")) {
                        new GetMyPublishGather(DataCenter.tour_category_id[0], userBeans.get(0).getUserid(), "31",currentPage).execute();
                    } else if (catids[a].equals("54")) {
                        new GetMyPublishSmall(DataCenter.tour_category_id[2], userBeans.get(0).getUserid(), "31",currentPage).execute();
                    } else if (catids[a].equals("56")) {
                        new PostMyMessageInfo(56, userBeans.get(0).getUserid(), "30",currentPage).execute();
                    }
                } else {
                    showToast(getText(R.string.no_network).toString());
                }
            }

            @Override
            public void onLoadMore() {
                if (DataCenter.userLogin.size() != 0) {
                    if (catids[a].equals("66")) {
                        new GetMyPublishAuction(DataCenter.pat_category_id[0] + "", userBeans.get(0).getUserid(), "17", ++currentPage).execute();
                    } else if (catids[a].equals("64")) {
                        new GetMyPublishSecondHandCar(DataCenter.secondHandCar_category_id, userBeans.get(0).getUserid(), "5", ++currentPage).execute();
                    } else if (catids[a].equals("65")) {
                        new GetMyPublishSecondHandHouse(DataCenter.secondHandHouse_category_id, userBeans.get(0).getUserid(), "28", ++currentPage).execute();
                    } else if (catids[a].equals("53")) {
                        new GetMyPublishGather(DataCenter.tour_category_id[0], userBeans.get(0).getUserid(), "31", ++currentPage).execute();
                    } else if (catids[a].equals("54")) {
                        new GetMyPublishSmall(DataCenter.tour_category_id[2], userBeans.get(0).getUserid(), "31", ++currentPage).execute();
                    } else if (catids[a].equals("56")) {
                        new PostMyMessageInfo(56, userBeans.get(0).getUserid(), "30", ++currentPage).execute();
                    }
                } else {
                    showToast(getText(R.string.no_network).toString());
                }
            }
        });

    }

    private void findActionBar() {
        actionBarView = (ActionBarView) findViewById(R.id.actionbar);
        actionBarView.setTitle("我的拍拍乐");
        showProgressDialog();
        new GetMyPublishAuction(DataCenter.pat_category_id[0] + "", userBeans.get(0).getUserid(), "17").execute();
        actionBarView.setTitleOnClick(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isClose = !isClose;
                if (isClose) {
                    closeTopBar();
                } else { //开启分类条
                    openTopBar();
                }
            }
        });
        actionBarView.setTitleIconIsUp(false);


        checkbox_category = actionBarView.checkBox;
        checkbox_category.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isShownTopBar()) {
                    closeTopBar();
                } else {
                    openTopBar();
                }
                checkbox_category.setChecked(isShownTopBar());
            }
        });
    }

    protected void openTopBar() {
        actionBarView.setTitleIconIsUp(true);
        categoryListview.setVisibility(View.VISIBLE);
        categoryListview.setAnimation(AnimationUtils.loadAnimation(this, R.anim.top_bar_in));
    }

    @Override
    protected void closeTopBar() {
        actionBarView.setTitleIconIsUp(false);
        categoryListview.setAnimation(AnimationUtils.loadAnimation(this, R.anim.top_bar_out));
        categoryListview.setVisibility(View.GONE);
    }

    @Override
    protected boolean isShownTopBar() {
        return categoryListview.getVisibility() == View.VISIBLE;
    }

    private void initCategoryData() {
        data = new ArrayList<Map<String, String>>();

        TreeMap<String, String> map = null;
        categoryTextArrays = getResources().getStringArray(R.array.myPublishCategory);

        for (int i = 0; i < categoryTextArrays.length; ++i) {
            map = new TreeMap<String, String>();
            map.put("title", categoryTextArrays[i]);
            data.add(map);
        }
    }


    @Override
    public void update(Observable observable, Object data) {
        DataCenter.flag flag = (DataCenter.flag) data;
        if (!HttpUtils.isConnected()) {
            baseList.onRefreshComplete();
            baseList.onLoadMoreComplete(false);
//            Toast.makeText(MyPublish.this, "网络连接错误,请稍后重试", Toast.LENGTH_SHORT).show();
        }

        closeProgressDialog();

        if (flag == DataCenter.flag.GET_MY_PUBLISH_SUCCESS
                || flag == DataCenter.flag.GET_MY_PUBLISH_FAILED) { //类表数据

            String code = DataCenter.code;
            if (flag == DataCenter.flag.GET_MY_PUBLISH_SUCCESS) {
                if (code.equals(DataCenter.successFlag)) {
                    closeProgressDialog();
                    Log.d("catid", catids[2]);
                    if (catids[a].equals("66")) {//拍拍乐
                        closeProgressDialog();
                        if (beansAuction.size() == 0 && currentPage <= 1) {
                            no_content_view.setVisibility(View.VISIBLE);
                            baseList.setVisibility(View.INVISIBLE);
                            ((TextView) no_content_view.findViewById(R.id.notice_msg_tv)).setText(R.string.listview_msg_empty_pub);
                        } else {
                            baseList.onLoadMoreComplete(false);
                            baseList.onRefreshComplete();
                            no_content_view.setVisibility(View.GONE);
                            baseList.setVisibility(View.VISIBLE);
                        }
                        if (o1 == 0) {
                            myAuctionAdapter = new MyAuctionAdapter(this, beansAuction, 1);
                            baseList.setAdapter(myAuctionAdapter);
                            o1 = 1;
                            myAuctionAdapter.notifyDataSetChanged();
                        } else {
                            myAuctionAdapter.notifyDataSetChanged();
                        }
                    } else if (catids[a].equals("64")) {//二手车

                        closeProgressDialog();
                        if (beansCar.size() == 0 && currentPage < 1) {
                            no_content_view.setVisibility(View.VISIBLE);
                            baseList.setVisibility(View.INVISIBLE);
                            ((TextView) no_content_view.findViewById(R.id.notice_msg_tv)).setText(R.string.listview_msg_empty_pub);
                        } else {
                            baseList.onLoadMoreComplete(false);
                            baseList.onRefreshComplete();
                            no_content_view.setVisibility(View.GONE);
                            baseList.setVisibility(View.VISIBLE);
                        }
                        if (o2 == 0) {
                            mySecondHandCarAdapter = new MySecondHandCarAdapter(this, beansCar, 1);
                            baseList.setAdapter(mySecondHandCarAdapter);
                            o2 = 1;
                            mySecondHandCarAdapter.notifyDataSetChanged();
                        } else {
                            mySecondHandCarAdapter.notifyDataSetChanged();
                        }

                    } else if (catids[a].equals("65")) {//二手房

                        closeProgressDialog();
                        if (beansHouse.size() == 0 && currentPage < 1) {
                            no_content_view.setVisibility(View.VISIBLE);
                            baseList.setVisibility(View.INVISIBLE);
                            ((TextView) no_content_view.findViewById(R.id.notice_msg_tv)).setText(R.string.listview_msg_empty_pub);
                        } else {
                            baseList.onLoadMoreComplete(false);
                            baseList.onRefreshComplete();
                            no_content_view.setVisibility(View.GONE);
                            baseList.setVisibility(View.VISIBLE);
                        }
                        if (o3 == 0) {
                            mySecondHandHouseAdapter = new MySecondHandHouseAdapter(this, beansHouse, 1);
                            baseList.setAdapter(mySecondHandHouseAdapter);
                            o3 = 1;
                            mySecondHandHouseAdapter.notifyDataSetChanged();
                        } else {
                            mySecondHandHouseAdapter.notifyDataSetChanged();
                        }
                    } else if (catids[a].equals("53")) {//召集
                        closeProgressDialog();
                        if (beansGather.size() == 0 && currentPage < 1) {
                            no_content_view.setVisibility(View.VISIBLE);
                            baseList.setVisibility(View.INVISIBLE);
                            ((TextView) no_content_view.findViewById(R.id.notice_msg_tv)).setText(R.string.listview_msg_empty_pub);
                        } else {
                            baseList.onLoadMoreComplete(false);
                            baseList.onRefreshComplete();
                            no_content_view.setVisibility(View.GONE);
                            baseList.setVisibility(View.VISIBLE);
                        }
                        if (o4 == 0) {
                            myTourGatherAdapter = new MyTourGatherAdapter(this, beansGather, 1);
                            baseList.setAdapter(myTourGatherAdapter);
                            myTourGatherAdapter.setOnCustomListener(new OnCustomerListener() {
                                @Override
                                public void onCustomerListener(View v, int position) {
                                    switch (v.getId()) {
                                        case R.id.tv_name:
                                            Intent i = new Intent(MyPublish.this, JoinConstactActivity.class);
                                            i.putExtra("userid", userBeans.get(0).getUserid());
                                            i.putExtra("itemid", beansGather.get(position).getItemid());
                                            startActivity(i);
                                            break;
                                        case R.id.myGatherItemButton:
                                            DataCenter.position = position;
                                            showProgressDialog();
                                            if (Integer.parseInt(beansGather.get(position).getStatus()) == 2) {
                                            new GetCloseOpen(DataCenter.userLogin.get(0).getUserid(), "open", DataCenter.beansGather.get(position).getItemid(), "31", DataCenter.tour_category_id[0] + "").execute();
                                        } else if (Integer.parseInt(beansGather.get(position).getStatus()) == 3) {
                                            new GetCloseOpen(DataCenter.userLogin.get(0).getUserid(), "close", DataCenter.beansGather.get(position).getItemid(), "31", DataCenter.tour_category_id[0] + "").execute();
                                        }
                                            break;
                                    }
                                }
                            });
                            o4 = 1;
                            myTourGatherAdapter.notifyDataSetChanged();
                        } else {
                            myTourGatherAdapter.notifyDataSetChanged();
                        }
                    } else if (catids[a].equals("54")) {//微记
                        closeProgressDialog();
                        if (beansSmall.size() == 0 && currentPage < 1) {
                            no_content_view.setVisibility(View.VISIBLE);
                            baseList.setVisibility(View.INVISIBLE);
                            ((TextView) no_content_view.findViewById(R.id.notice_msg_tv)).setText(R.string.listview_msg_empty_pub);
                        } else {
                            baseList.onLoadMoreComplete(false);
                            baseList.onRefreshComplete();
                            no_content_view.setVisibility(View.GONE);
                            baseList.setVisibility(View.VISIBLE);
                        }
                        if (o5 == 0) {
                            myTourSmallNoteAdapter = new MyTourSmallNoteAdapter(this, beansSmall, 1);
                            baseList.setAdapter(myTourSmallNoteAdapter);
                            o5 = 1;
                            myTourSmallNoteAdapter.notifyDataSetChanged();
                        } else {
                            myTourSmallNoteAdapter.notifyDataSetChanged();
                        }
                    } else if (catids[a].equals("56")) {
                        closeProgressDialog();
                        messageBeans = DataCenter.messageInfoList;
                        if (messageBeans.size() == 0) {
                            no_content_view.setVisibility(View.VISIBLE);
                            baseList.setVisibility(View.INVISIBLE);
                            ((TextView) no_content_view.findViewById(R.id.notice_msg_tv)).setText(R.string.listview_msg_empty_pub);
                        } else {
                            baseList.onLoadMoreComplete(false);
                            baseList.onRefreshComplete();
                            no_content_view.setVisibility(View.GONE);
                            baseList.setVisibility(View.VISIBLE);
                        }
                        if (o == 0) {
                            messageAdapter = new MessageAdapter(this, messageBeans, 1);
                            baseList.setAdapter(messageAdapter);
                            o = 1;
                            messageAdapter.notifyDataSetChanged();
                        } else {
                            messageAdapter.notifyDataSetChanged();
                        }
                    }
                    //Toast.makeText(MyPublish.this, DataCenter.msg, Toast.LENGTH_SHORT).show();
                } else {
                    closeProgressDialog();
//                    Toast.makeText(MyPublish.this, DataCenter.msg, Toast.LENGTH_SHORT).show();
//                    Toast.makeText(MyPublish.this, "网络异常", Toast.LENGTH_SHORT).show();
                    return;
                }
            }

            if (flag == DataCenter.flag.GET_MY_PUBLISH_FAILED) {
                closeProgressDialog();
//                Toast.makeText(MyPublish.this, DataCenter.msg, Toast.LENGTH_SHORT).show();
//                Toast.makeText(MyPublish.this, "网络异常", Toast.LENGTH_SHORT).show();
            }
        }

        if (flag == DataCenter.flag.GET_CLOSE_OR_OPEN_SUCCESS || flag == DataCenter.flag.GET_CLOSE_OR_OPEN_FAILED) {

            if (flag == DataCenter.flag.GET_CLOSE_OR_OPEN_SUCCESS) {
                if (catids[a].equals("65")) {
                    new GetMyPublishSecondHandHouse(DataCenter.secondHandHouse_category_id, userBeans.get(0).getUserid(), "28",currentPage).execute();
                    closeProgressDialog();
                } else if (catids[a].equals("64")) {
                    new GetMyPublishSecondHandCar(DataCenter.secondHandCar_category_id, userBeans.get(0).getUserid(), "5",currentPage).execute();
                    closeProgressDialog();
                } else if (catids[a].equals("54")) {
                    new GetMyPublishSmall(DataCenter.tour_category_id[2], userBeans.get(0).getUserid(), "31",currentPage).execute();
                    closeProgressDialog();
                } else if (catids[a].equals("66")) {
                    new GetMyPublishAuction(DataCenter.pat_category_id[0] + "", userBeans.get(0).getUserid(), "17",currentPage).execute();
                    closeProgressDialog();
                } else if (catids[a].equals("53")) {
                    new GetMyPublishGather(DataCenter.tour_category_id[0], userBeans.get(0).getUserid(), "31",currentPage).execute();
                    closeProgressDialog();
                } else if (catids[a].equals("56")) {
                    new PostMyMessageInfo(56, userBeans.get(0).getUserid(), "30",currentPage).execute();
                    closeProgressDialog();
                }
                Toast.makeText(MyPublish.this, DataCenter.msg, Toast.LENGTH_SHORT).show();

            } else {
                Toast.makeText(MyPublish.this, "错误操作", Toast.LENGTH_SHORT).show();
                return;
            }
        }

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        LogUtil.d(DataCenter.LOG_INFO, MyPublish.class.getSimpleName() + ".onDestroy");
        //删除观察者
        DataCenter.getInstance().deleteObserver(this);
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK || event.getKeyCode() == KeyEvent.KEYCODE_MENU) {
            if (isShownTopBar()) {
                actionBarView.checkBox.setChecked(false);
                isClose = true;
                closeTopBar();
                return false;
            }
        }
        return super.dispatchKeyEvent(event);
    }


}